<?php
//echo $this->dojo();
$urlParams = array();


foreach(Zend_Controller_Front::getInstance()->getRequest()->getUserParams() as $key => $value)
{	
	$urlParams[] = urlencode($key) . '/' . urlencode($value);
	}
$urlParams = implode('/', $urlParams);
?>

<h2><?= $this->classType->getDisplayValue() ?> List</h2>
<button dojoType='dijit.form.Button' onClick="window.location = '<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/add-instance/class_type_id/<?= $this->classType->class_type_id?>';">Add</button>

<script>
viewRecord = function(e)
{
	var newUrl = '<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/view-instance/class_type_id/<?= $this->classType->class_type_id ?>/class_instance_id/' + this.store.getValue(this.getItem(e.rowIndex), 'class_instance_id');
	//newModalDialog({title: 'Detail', style: 'width:770px;', href: newUrl});
	window.location=newUrl;
}
rowsetLayout = 
	[
		[
<?php 

		
		$classFieldTypes = $this->classType->findBushido_DbTable_ClassFieldType(Bushido_Db_Table::getTable('Bushido_DbTable_ClassFieldType')->select()->order('order ASC'));
		foreach($classFieldTypes as $classFieldType)
		{
		?>
			{field: "<?= 'field_type_2_class_type_' . $classFieldType->field_type_2_class_type_id ?>", name: "<?= $classFieldType->label ?>", width: 'auto'},
		<?php
		}
		?>
		]
	];

</script>
<span dojoType="dojo.data.ItemFileReadStore" id="gridStore" jsId="gridStore" url="<?= Zend_Controller_Front::getInstance()->getBaseUrl() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getModuleName() ?>/<?= Zend_Controller_Front::getInstance()->getRequest()->getControllerName() ?>/list-instances-json/<?= $urlParams ?>" ></span>
<div style="height:200px;"
dojoType="dojox.grid.DataGrid"
store="gridStore"
query="{}"
onRowClick="viewRecord"
structure="rowsetLayout"
rowsPerPage="40">
  </div>